package com.ruoyi.quan.controller;

import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quan.domain.QContent;
import com.ruoyi.quan.service.IQContentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 内容生产Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/quan/content")
public class QContentController extends BaseController
{
    @Autowired
    private IQContentService qContentService;

    /**
     * 查询内容生产列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QContent qContent)
    {
        startPage();
        List<QContent> list = qContentService.selectQContentList(qContent);
        return getDataTable(list);
    }

    /**
     * 导出内容生产列表
     */
    @Log(title = "内容生产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QContent qContent)
    {
        List<QContent> list = qContentService.selectQContentList(qContent);
        ExcelUtil<QContent> util = new ExcelUtil<QContent>(QContent.class);
        util.exportExcel(response, list, "内容生产数据");
    }

    /**
     * 获取内容生产详细信息
     */
    @GetMapping(value = "/{componentId}")
    public AjaxResult getInfo(@PathVariable("componentId") Long componentId)
    {
        return success(qContentService.selectQContentByComponentId(componentId));
    }

    /**
     * 新增内容生产
     */
    @Log(title = "内容生产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QContent qContent)
    {
        // 如果创建时间为空，设置为当前时间
        if (qContent.getCreateTime() == null) {
            qContent.setCreateTime(new Date());
        }
        return toAjax(qContentService.insertQContent(qContent));
    }

    /**
     * 修改内容生产
     */
    @Log(title = "内容生产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QContent qContent)
    {
        // 更新时间设置为当前时间
        if (qContent.getUpdateTime() == null) {
            qContent.setUpdateTime(new Date());
        }
        return toAjax(qContentService.updateQContent(qContent));
    }

    /**
     * 删除内容生产
     */
    @Log(title = "内容生产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{componentIds}")
    public AjaxResult remove(@PathVariable Long[] componentIds)
    {
        return toAjax(qContentService.deleteQContentByComponentIds(componentIds));
    }
} 